import {workOrderContentComponents} from './config/index.js'
import {getInput,getSelect,createIdAndKey} from './config/create.js'
import {deepClone, assign} from '../../utils/index.js'

let card = deepClone(workOrderContentComponents[0])

assign(card, {
  __config__: {
    label: '工单基本信息',
    group: 'workOrderContentComponents',
    showUpBtn: false,
    showDownBtn: false,
    showDeleteButton: false,
    children: {
      cardBody: [
        getInput({
          __config__: {label: '工单编号'},placeholder: '自动生成'
        }),
        getInput({
          __config__: {label: '工单来源'},placeholder: '自动生成'
        }),
        getInput({
          __config__: {label: '工单名称'},placeholder: '自动生成'
        }),
        getInput({
          __config__: {label: '创建人'},placeholder: '自动带入创建人账号姓名'
        }),
        getInput({
          __config__: {label: '联系人'},placeholder: '自动带入用户账号/可自行编辑手机号码'
        }),
        getSelect({
          __config__: {label: '归属单位'},__slot__: {
            options: [
              {
                label: "蜀道集团",
                value: 1,
              },
              {
                label: "路桥公司",
                value: 2,
              },
            ],
          },
        })
      ]
    }
  }
})
card.__config__.startDragIndex = card.__config__.children.cardBody.length
card.__config__.checkMove = function(evt){
  // 获取拖动元素的索引和目标位置的索引
  const dragIndex = evt.draggedContext.index;
  const targetIndex = evt.relatedContext.index;
  // console.log(dragIndex, targetIndex);
  // console.log('targetIndex', targetIndex, 'startDragIndex',card.config.startDragIndex)
  let startDragIndex = card.__config__.startDragIndex
  if(startDragIndex !== undefined && targetIndex < startDragIndex-1){
    return false
  }
  if (targetIndex === startDragIndex-1) {
    return 1
  }
},
createIdAndKey(card)
card.__config__.children.cardBody.forEach(item => {
  createIdAndKey(item)
})
export default [
  card
]
